import cv2 as cv
import numpy as np


def extract_video_demo():
    capture = cv.VideoCapture('sample1.mp4')
    while True:
        ret, frame = capture.read()
        if not ret:
            break
        lower_hsv = np.array([110,50,50])
        upper_hsv = np.array([130, 255, 255])
        hsv = cv.cvtColor(frame,cv.COLOR_BGR2HSV)
        mask = cv.inRange(hsv, lowerb=lower_hsv, upperb=upper_hsv)
        dst = cv.bitwise_and(frame, frame, mask=mask)
        # cv.imshow('sample1', frame)
        cv.imshow('mask', dst)
        key = cv.waitKey(20)
        if key == 27:
            break


def img_color_cvt(img):
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    cv.imshow('gray', gray)
    hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
    cv.imshow('hsv', hsv)
    hls = cv.cvtColor(img, cv.COLOR_BGR2HLS)
    cv.imshow('hls', hls)
    yuv = cv.cvtColor(img, cv.COLOR_BGR2YUV)
    cv.imshow('yuv', yuv)
    ycrcb = cv.cvtColor(img, cv.COLOR_BGR2YCrCb)
    cv.imshow('ycrcb', ycrcb)


img = cv.imread('lena.jpg', 1)
cv.imshow('lena', img)
# img_color_cvt(img)
extract_video_demo()
# b, g, r = cv.split(img)
# cv.imshow('blue', b)
# cv.imshow('green', g)
# cv.imshow('red', r)
#
# merged = cv.merge([b, g, r])
# cv.imshow('merged', merged)
#
# merged[:, :, 0] = 0
# cv.imshow('0-0', merged)
# img[:, :, 2] = 0
# cv.imshow('2-0', img)
cv.waitKey(0)
cv.destroyWindow('lena')
